package com.app.service.impl;

import com.app.dao.mysql.YjDataMapper;
import com.app.domain.JsonResult;
import com.app.domain.YjData;
import com.app.domain.jwjb.YjDataTime;
import com.app.service.YjDataService;
import com.app.utils.MathUtil;
import com.app.utils.TimeHelper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Time;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
@Transactional
public class YjDataServiceImpl implements YjDataService {
    @Autowired
    YjDataMapper yjDataMapper;

    @Override
    public YjData findOne(String id) {
        return yjDataMapper.findOne(id);
    }

    @Override
    public List<YjData> findList(String[] ids) {
        return yjDataMapper.findList(ids);
    }

    @Override

    public JsonResult selectList(String bridgeCode, String device_code, String state, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<YjData> yjData = yjDataMapper.selectList(bridgeCode, device_code, state);
        PageInfo pageInfo = new PageInfo(yjData);
        return JsonResult.success(pageInfo.getList(), pageInfo.getTotal());
    }

    @Override
    public JsonResult selectList(String bridgeCode, String[] device_code, String state, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<YjData> yjData = yjDataMapper.selectDeviceCodesList(bridgeCode, device_code, state);
        PageInfo pageInfo = new PageInfo(yjData);
        return JsonResult.success(pageInfo.getList(), pageInfo.getTotal());
    }

    @Override
    public void updateById(String state, String id) {
        yjDataMapper.updateById(state, id);
    }

    @Override
    public int updateStateById(String state, String id) {
        return yjDataMapper.updateStateById(state, id);
    }

    @Override
    public String ConditionUpdate(String id, String field, String value) {
        String s;
        try {
            yjDataMapper.ConditionUpdate(id, field, value);
            s = "修改成功";
        } catch (Exception e) {
            s = "修改失败";
            e.printStackTrace();
        }
        return s;
    }

    @Override
    public String save(String deviceCode, String bridgeCode, String mudjackDate) {
        String startTime = null;
        String maxEndTime = yjDataMapper.findMaxEndTime(deviceCode, mudjackDate);
        List<YjData> yjDataList = new ArrayList<>();
        for (int i = 1; i <= 8; i++) {
            YjData yjData = new YjData();
            yjData.setBridge_code(bridgeCode);
            yjData.setDevice_code(deviceCode);
            yjData.setDuct_code("N" + i);
            yjData.setMudjack_date(mudjackDate);
            if (i == 1) {
                if (maxEndTime != null) {
                    long j = (long) (900000 + Math.random() * (600000 - 900000 + 1));
                    String startDate = TimeHelper.timeStamp2Date(String.valueOf(TimeHelper.getTimestamp(mudjackDate + " " + maxEndTime, "yyyy-MM-dd HH:mm:ss") + j), "yyyy-MM-dd HH:mm:ss");
                    startTime = startDate.split(" ")[1];
                } else {
                    startTime = TimeHelper.randomDate("07:00:00", "08:00:00");
                }
            }

            yjData.setBegin_time(startTime);
            long j = (long) (90000 + Math.random() * (150000 - 90000 + 1));
            yjData.setEnd_time(TimeHelper.timeStamp2Date(String.valueOf(TimeHelper.getTimestamp(mudjackDate + " " + startTime, "yyyy-MM-dd HH:mm:ss") + j), "yyyy-MM-dd HH:mm:ss").split(" ")[1]
            );

            yjData.setMudjack_pressure(MathUtil.getRandomFloat(0.5f, 0.7f));
            yjData.setSlurry_pressure(MathUtil.getRandomFloat(0.5f, 0.7f));
            yjData.setStabilize_pressure(MathUtil.getRandomFloat(0.5f, 0.7f));
            yjData.setPressurize_time("180");
            yjData.setWater_binder_ratio(0.28f);
            yjData.setTheory_volume(120f);
            yjData.setPractical_volume(140f);
            yjData.setPractical_mudjack_value(107.69f);
            yjData.setPractical_water_value(32.31f);
            yjData.setEnvironment_temperature(5f);
            yjData.setSlurry_temperature(22.5f);
            yjData.setPractical_fluidity("17");
            yjData.setRemark("");
            yjData.setMudjack_curve_graph("");
            yjData.setState("2");
            long jj = (long) (120000 + Math.random() * (300000 - 120000 + 1));
            startTime = TimeHelper.timeStamp2Date(String.valueOf(TimeHelper.getTimestamp(mudjackDate + " " + startTime, "yyyy-MM-dd HH:mm:ss") + jj), "yyyy-MM-dd HH:mm:ss").split(" ")[1];
//            System.out.println(yjData);
            yjDataList.add(yjData);
        }

        String s;
        try {
            for (YjData yjData : yjDataList) {
                yjDataMapper.save(yjData);
            }
            s = "保存成功";
        } catch (Exception e) {
            s = "保存失败";
            e.printStackTrace();
        }
        return s;
    }

    @Override
    public String selectMcg(String device_code, String bridge_code) {
        return yjDataMapper.selectMcg(device_code, bridge_code);
    }

    @Override
    public String selectOneMcg(String device_code, String bridge_code, String duct_code) {
        return yjDataMapper.selectOneMcg(device_code, bridge_code, duct_code);
    }

    @Override
    public Float sumPmv(String device_code, String bridge_code) {
        return yjDataMapper.sumPmv(device_code, bridge_code);
    }

    @Override
    public Float onePmv(String device_code, String bridge_code, String duct_code) {
        return yjDataMapper.onePmv(device_code, bridge_code, duct_code);
    }

    @Override
    public List<YjDataTime> findStartAndEndTime(String device_code, String bridge_code) {
        return yjDataMapper.findStartAndEndTime(device_code, bridge_code);
    }

    @Override
    public List<YjData> findYjDataListById(String id) {
        return yjDataMapper.findYjDataListById(id);
    }


    @Override
    public List<YjData> findYjdataByDeviceCodAndBridgeCode(String device_code, String bridge_code) {
        return yjDataMapper.findYjdataByDeviceCodAndBridgeCode(device_code, bridge_code);
    }

    @Override
    public Map<String, Object> findDate(List<Integer> ids) {
        return yjDataMapper.findDate(ids);
    }

    @Override
    public JsonResult selectList1(String bridgeCode, String device_code, String mudjackDate, String state, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<YjData> yjData = yjDataMapper.selectMudjackDateList(bridgeCode, device_code, mudjackDate, state);
        PageInfo pageInfo = new PageInfo(yjData);
        return JsonResult.success(pageInfo.getList(), pageInfo.getTotal());
    }

    @Override
    public Map<String, List> getNewGraphData(String id) {
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        List<String> list3 = new ArrayList<>();
        List<Float> list4 = new ArrayList<>();
        List<Float> list5 = new ArrayList<>();

        YjDataTime yjDataTime = yjDataMapper.findStartAndEndTimeById(id);
        Long subTime = TimeHelper.subTime(yjDataTime.getStartTime(), yjDataTime.getEndTime());
        int ii = (int) Math.floor(subTime / 5);
        YjData one = yjDataMapper.findOne(id);
        String mudjack_curve_graph = one.getMudjack_curve_graph();
        String mudjack_curve_out_graph = one.getMudjack_curve_out_graph();

        if (StringUtils.isEmpty(mudjack_curve_graph)) {
            list2.addAll(getGraphData(id).get("mcgList"));
            list3.addAll(getGraphData(id).get("mcgList"));
        } else {
            //进浆压力曲线
            Collections.addAll(list2, mudjack_curve_graph.split(","));
            //出浆压力曲线
            Collections.addAll(list3, mudjack_curve_out_graph.split(","));
        }

        //进浆量曲线

        DecimalFormat dd = new DecimalFormat("#.00");
        Float practical_volume = one.getPractical_volume();

        float v = practical_volume / ii;
        Float f = 0f;
        list4.add(f);
        for (int i = 0; i < ii; i++) {
            f = v + f;
            list4.add(Float.valueOf(dd.format(f)));
        }

        //出浆量曲线
        Float practical_mudjack_value = one.getPractical_mudjack_value();
        float p = practical_mudjack_value / ii;
        Float f1 = 0f;
        list5.add(f1);
        for (int i = 0; i < ii; i++) {
            f1 = p + f1;
            list5.add(Float.valueOf(dd.format(f1)));
        }

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = null;
        try {
            parse = df.parse(yjDataTime.getStartTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String format;
        list1.add(yjDataTime.getStartTime().split(" ")[1]);
        for (int i = 0; i < ii; i++) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(parse);
            calendar.add(Calendar.SECOND, +5);
            parse = calendar.getTime();
            format = df.format(calendar.getTime());
            list1.add(format.split(" ")[1]);
        }
        Map<String, List> map = new HashMap<>();
        map.put("dateList", list1);
        map.put("mcgList", list2);
        map.put("mcgOutList", list3);
        map.put("mcgVolumeInList", list4);
        map.put("mcgVolumeOutList", list5);
        return map;
    }

    @Override
    public Map<String, List> getNewGraphData2(String id) {
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        List<String> list3 = new ArrayList<>();
        List<Float> list4 = new ArrayList<>();
        List<Float> list5 = new ArrayList<>();

        YjDataTime yjDataTime = yjDataMapper.findStartAndEndTimeById(id);
        Long subTime = TimeHelper.subTime(yjDataTime.getStartTime(), yjDataTime.getEndTime());
        int ii = (int) Math.floor(subTime / 5);
        YjData one = yjDataMapper.findOne(id);

        list2.addAll(getGraphData(id).get("mcgList"));
        list3.addAll(getGraphData(id).get("mcgList"));
       /*  String mudjack_curve_graph = one.getMudjack_curve_graph();
        String mudjack_curve_out_graph = one.getMudjack_curve_out_graph();
       if (StringUtils.isEmpty(mudjack_curve_graph)){
            list2.addAll(getGraphData(id).get("mcgList"));
            list3.addAll(getGraphData(id).get("mcgList"));
        }else {
            //进浆压力曲线
            Collections.addAll(list2, mudjack_curve_graph.split(","));
            //出浆压力曲线
            Collections.addAll(list3, mudjack_curve_out_graph.split(","));
        }*/

        //进浆量曲线

        DecimalFormat dd = new DecimalFormat("#.00");
        Float practical_volume = one.getPractical_volume();

        float v = practical_volume / ii;
        Float f = 0f;
        list4.add(f);
        for (int i = 0; i < ii; i++) {
            f = v + f;
            list4.add(Float.valueOf(dd.format(f)));
        }

        //出浆量曲线
        Float practical_mudjack_value = one.getPractical_mudjack_value();
        float p = practical_mudjack_value / ii;
        Float f1 = 0f;
        list5.add(f1);
        for (int i = 0; i < ii; i++) {
            f1 = p + f1;
            list5.add(Float.valueOf(dd.format(f1)));
        }

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = null;
        try {
            parse = df.parse(yjDataTime.getStartTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String format;
        list1.add(yjDataTime.getStartTime().split(" ")[1]);
        for (int i = 0; i < ii; i++) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(parse);
            calendar.add(Calendar.SECOND, +5);
            parse = calendar.getTime();
            format = df.format(calendar.getTime());
            list1.add(format.split(" ")[1]);
        }
        Map<String, List> map = new HashMap<>();
        map.put("dateList", list1);
        map.put("mcgList", list2);
        map.put("mcgOutList", list3);
        map.put("mcgVolumeInList", list4);
        map.put("mcgVolumeOutList", list5);
        return map;
    }

    @Override
    public Map<String, List> getGasbGraphData(String id) {
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        List<String> list3 = new ArrayList<>();


        YjDataTime yjDataTime = yjDataMapper.findStartAndEndTimeById(id);
        Long subTime = TimeHelper.subTime(yjDataTime.getStartTime(), yjDataTime.getEndTime());
        int ii = (int) Math.floor(subTime / 5);
        YjData one = yjDataMapper.findOne(id);
        list2.addAll(getGraphData(id).get("mcgList"));
        list3.addAll(getGraphData(id).get("mcgList"));
        //进浆量曲线

        DecimalFormat dd = new DecimalFormat("#.00");
        Float practical_volume = one.getPractical_volume();


        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = null;
        try {
            parse = df.parse(yjDataTime.getStartTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String format;
        list1.add(yjDataTime.getStartTime().split(" ")[1]);
        for (int i = 0; i < ii; i++) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(parse);
            calendar.add(Calendar.SECOND, +5);
            parse = calendar.getTime();
            format = df.format(calendar.getTime());
            list1.add(format.split(" ")[1]);
        }
        Map<String, List> map = new HashMap<>();
        map.put("dateList", list1);
        map.put("mcgList", list2);
        map.put("mcgOutList", list3);
        return map;
    }

    @Override
    public Map<String, List> getGraphData(String id) {
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        YjDataTime yjDataTime = yjDataMapper.findStartAndEndTimeById(id);
        String mcgById = yjDataMapper.findMcgById(id);
        Long subTime = TimeHelper.subTime(yjDataTime.getStartTime(), yjDataTime.getEndTime());
        int ii = (int) Math.floor(subTime / 5);
        int a = (int) Math.floor(ii / 10);
        String[] split = mcgById.split("-");
        /*      if (ii > split.length) {*/
        if (a == 0) {
            list2.add("0");
            for (int i = 1; i < ii - 1; i++) {
                double randomDouble = MathUtil.getRandomDouble(0.5, 0.65);
                list2.add(Double.toString(randomDouble));
           /*     Collections.sort(list2, new Comparator<String>() {
                    @Override
                    public int compare(String s1, String s2) {
                        return s1.compareTo(s2);
                    }
                });*/
            }
            list2.add("0");
        } else {
            list2.add("0");
            List<Double> num = new ArrayList<>();
            for (int j = 0 + 1; j < a; j++) {
                double randomDouble = MathUtil.getRandomDouble(0, 0.3);

                num.add(randomDouble);


            }
            Collections.sort(num, new Comparator<Double>() {
                @Override
                public int compare(Double s1, Double s2) {
                    return s1.compareTo(s2);
                }
            });
            for (Double aDouble : num) {
                list2.add(Double.toString(aDouble));
            }
            for (int i = 0 + a; i < ii - a; i++) {
                double randomDouble = MathUtil.getRandomDouble(0.5, 0.65);
                list2.add(Double.toString(randomDouble));
            }
            List<Double> num1 = new ArrayList<>();
            for (int e = ii - a; e < ii + 1; e++) {
//                    double randomDouble = MathUtil.getRandomDouble(0, 0.3);

                list2.add("0");

            }
              /*  Collections.sort(num, Collections.reverseOrder(new Comparator<Double>() {

                    @Override
                    public int compare(Double s1, Double s2) {
                        return s1.compareTo(s2);
                    }
                }));*/
              /*  num1.sort((o1, o2) -> {

                            return o1.compareTo(o2);
                        });
                for (Double aDouble : num1) {
                    list2.add(String.valueOf(aDouble));
                }*/
        }

        /*} else {
            log.info("234");
            String[] newData;
            newData = Arrays.copyOfRange(split, split.length - ii - 1, split.length);
            list2 = Arrays.asList(newData);
        }*/
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = null;
        try {
            parse = df.parse(yjDataTime.getStartTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String format;
        list1.add(yjDataTime.getStartTime().split(" ")[1]);
        for (int i = 0; i < ii; i++) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(parse);
            calendar.add(Calendar.SECOND, +5);
            parse = calendar.getTime();
            format = df.format(calendar.getTime());
            list1.add(format.split(" ")[1]);
        }
        Map<String, List> map = new HashMap<>();
        map.put("dateList", list1);
        map.put("mcgList", list2);
        return map;
    }

    @Override
    public Map<String, List> getGraphData4(String id) {
        List<Double> list2 = new ArrayList<>();
        YjDataTime yjDataTime = yjDataMapper.findStartAndEndTimeById(id);
        String mcgById = yjDataMapper.findMcgById(id);
        Long subTime = TimeHelper.subTime(yjDataTime.getStartTime(), yjDataTime.getEndTime());
//        int ii = (int) Math.floor(subTime / 5);

        if (subTime < 300) {
            list2.add(0.0);
            for (int i = 1; i < subTime - 1; i++) {
                double randomDouble = MathUtil.getRandomDouble(0.5, 0.65);
                list2.add(randomDouble);
           /*     Collections.sort(list2, new Comparator<String>() {
                    @Override
                    public int compare(String s1, String s2) {
                        return s1.compareTo(s2);
                    }
                });*/
            }
            list2.add(0.0);
        } else {

            List<Double> num = new ArrayList<>();
            for (int j = 0; j <= 350; j++) {
//                double randomDouble = MathUtil.getRandomDouble(0, 0.15);

                num.add(0.0);


            }
          /*  Collections.sort(num, new Comparator<Double>() {
                @Override
                public int compare(Double s1, Double s2) {
                    return s1.compareTo(s2);
                }
            });*/
            int floor = (int) Math.floor((subTime - 350) / 8);
            List<Double> num1 = new ArrayList<>();
            List<Double> num2 = new ArrayList<>();
            for (int i = 0; i < floor; i++) {
                double randomDouble = MathUtil.getRandomDouble(0.5, 1.2);

                num1.add(randomDouble);
                double randomDouble1 = MathUtil.getRandomDouble(0.2, 0.4);

                num2.add(randomDouble1);
            }
            num1 = num1.stream()
                    .sorted(Comparator.comparingDouble(Double::doubleValue).reversed())
                    .collect(Collectors.toList());

            num2 = num2.stream()
                    .sorted(Comparator.comparingDouble(Double::doubleValue).reversed())
                    .collect(Collectors.toList());
            for (int i = 0; i < num1.size(); i++) {
                num.add(num1.get(i));
                num.add(BigDecimalCal(num1.get(i), "-", num2.get(i)));
            }
            int f = (int) Math.floor(((subTime - 350) - (floor * 2)) / 2);
            for (int j = 0; j < f; j++) {
                double randomDouble = MathUtil.getRandomDouble(0.38, 0.42);
                double randomDouble1 = MathUtil.getRandomDouble(0.02, 0.04);
                num.add(randomDouble);
                num.add(BigDecimalCal(randomDouble, "-", randomDouble1));
            }
            list2.addAll(num);

        }

        Map<String, List> map = new HashMap<>();
        map.put("mcgList", list2);
        return map;
    }

    @Override
    public Map<String, List> getGraphData3(String id) {
        List<String> list1 = new ArrayList<>();
        List<Double> list2 = new ArrayList<Double>();
        YjDataTime yjDataTime = yjDataMapper.findStartAndEndTimeById(id);
        String mcgById = yjDataMapper.findMcgById(id);
        Long subTime = TimeHelper.subTime(yjDataTime.getStartTime(), yjDataTime.getEndTime());
//        int ii = (int) Math.floor(subTime / 1);
//        int a = (int) Math.floor(ii / 2);
//        String[] split = mcgById.split("-");
        /*      if (ii > split.length) {*/
        if (subTime < 300) {
            list2.add(0.0);
            for (int i = 1; i < subTime - 1; i++) {
                double randomDouble = MathUtil.getRandomDouble(0.5, 0.65);
                list2.add(randomDouble);
           /*     Collections.sort(list2, new Comparator<String>() {
                    @Override
                    public int compare(String s1, String s2) {
                        return s1.compareTo(s2);
                    }
                });*/
            }
            list2.add(0.0);
        } else {
            list2.add(0.0);
            List<Double> num = new ArrayList<>();
            for (int j = 0; j < 350; j++) {
                double randomDouble = MathUtil.getRandomDouble(0, 0.15);

                num.add(randomDouble);


            }
            num = num.stream()
                    .sorted(Comparator.comparingDouble(Double::doubleValue))
                    .collect(Collectors.toList());
          /*  Collections.sort(num, new Comparator<Double>() {
                @Override
                public int compare(Double s1, Double s2) {
                    return s1.compareTo(s2);
                }
            });*/
            int floor = (int) Math.floor((subTime - 350) / 8);
            List<Double> num1 = new ArrayList<>();
            List<Double> num2 = new ArrayList<>();
            for (int i = 0; i < floor; i++) {
                double randomDouble = MathUtil.getRandomDouble(0.5, 0.8);

                num1.add(randomDouble);
                double randomDouble1 = MathUtil.getRandomDouble(0.1, 0.3);

                num2.add(randomDouble1);
            }
            num1 = num1.stream()
                    .sorted(Comparator.comparingDouble(Double::doubleValue).reversed())
                    .collect(Collectors.toList());

            num2 = num2.stream()
                    .sorted(Comparator.comparingDouble(Double::doubleValue).reversed())
                    .collect(Collectors.toList());
            for (int i = 0; i < num1.size(); i++) {
                num.add(num1.get(i));
                num.add(BigDecimalCal(num1.get(i), "-", num2.get(i)));
            }
            int f = (int) Math.floor(((subTime - 350) - (floor * 2)) / 2);
            for (int j = 0; j < f; j++) {
                double randomDouble = MathUtil.getRandomDouble(0.24, 0.28);
                double randomDouble1 = MathUtil.getRandomDouble(0.02, 0.03);
                num.add(randomDouble);
                num.add(BigDecimalCal(randomDouble, "-", randomDouble1));
            }
            list2.addAll(num);

        }

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = null;
        try {
            parse = df.parse(yjDataTime.getStartTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String format;
        list1.add(yjDataTime.getStartTime().split(" ")[1]);
        for (int i = 0; i < subTime; i++) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(parse);
            calendar.add(Calendar.SECOND, +5);
            parse = calendar.getTime();
            format = df.format(calendar.getTime());
            list1.add(format.split(" ")[1]);
        }
        Map<String, List> map = new HashMap<>();
        map.put("dateList", list1);
        map.put("mcgList", list2);
        return map;
    }

    public static Double BigDecimalCal(Double d1, String operation, Double d2) {
        BigDecimal bd = new BigDecimal("0");
        if (d1 != null && d2 != null) {
            if ("+".equals(operation)) {
                bd = new BigDecimal(String.valueOf(d1)).add(new BigDecimal(String.valueOf(d2)));
            } else if ("-".equals(operation)) {
                bd = new BigDecimal(String.valueOf(d1)).subtract(new BigDecimal(String.valueOf(d2)));
            } else if ("*".equals(operation)) {
                bd = new BigDecimal(String.valueOf(d1)).multiply(new BigDecimal(String.valueOf(d2)));
            } else if ("/".equals(operation)) {
                bd = new BigDecimal(String.valueOf(d1)).divide(new BigDecimal(String.valueOf(d2)), 6, RoundingMode.HALF_UP);
            }
        }
        return bd.doubleValue();
    }

    @Override
    public Map<String, List> getGraphData2(String id) {
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        YjDataTime yjDataTime = yjDataMapper.findStartAndEndTimeById(id);
//        String mcgById = yjDataMapper.findMcgById(id);
        Long subTime = TimeHelper.subTime(yjDataTime.getStartTime(), yjDataTime.getEndTime());
        int ii = (int) (subTime / 5);


        for (int i = 0; i < ii; i++) {
            double randomDouble = MathUtil.getRandomDouble(0.5, 0.7);
            list2.add(Double.toString(randomDouble));
            Collections.sort(list2, new Comparator<String>() {
                @Override
                public int compare(String s1, String s2) {
                    return s1.compareTo(s2);
                }
            });
        }

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = null;
        try {
            parse = df.parse(yjDataTime.getStartTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String format;
        list1.add(yjDataTime.getStartTime().split(" ")[1]);
        for (int i = 0; i < ii; i++) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(parse);
            calendar.add(Calendar.SECOND, +5);
            parse = calendar.getTime();
            format = df.format(calendar.getTime());
            list1.add(format.split(" ")[1]);
        }
        Map<String, List> map = new HashMap<>();
        map.put("dateList", list1);
        map.put("mcgList", list2);
        return map;
    }
}
